function [conv_crit, A, K] = endsignals_ru_fp(r, param,yi,eps_etai,reset_shocks,util_type, smooth_wind, stateGrid_size,log_c, p_unemp, w_unemp, ex_signals, int_nodes, int_weights,normpdf_nodes)

bta = param(1);
abar = param(3);
W_cc = param(4);
kappa = param(5);
deltax = param(6);
sigma_c = param(7);
psi = param(8);
cov_fun = param(9);
gam = param(10);
sigma_l = param(11);
lbar = param(12);
delta_eta = param(13);
delta_inh= param(14);
delta    = param(15);
alpha    = param(16);
b        = param(17);
btat     = param(18);
amin     = param(19);
amax     = param(20);
na       = param(21);
crit_dist = param(22); 

% Step 1: get aggregate capital and wage implied by r
K = ((r + delta)/alpha)^(1/(alpha-1)); % Aggregate demand of capital (from firm k-FOC)
w = (1-alpha).*K.^alpha; % Wage (from firm l-FOC)

% Step 2: get optimal policy function
rt = (r*(1-deltax*delta_inh) + deltax*(1-delta_inh))./(1-deltax); % effective interest rate (includes insurance market)

[xs,~,cstar,~,ctilde] = bc_opt_pol_iid_egm(btat, rt, b, log(w) + lbar, sigma_l, gam, amin, amax, na, util_type, p_unemp, w_unemp);

%disp('policy computed'); 

[xs,xi] = unique(xs);

% get policy function over an equally spaced grid
stateGrid = linspace( min(xs(:)), max(xs(:)),stateGrid_size);
stateGrid_step = stateGrid(2) - stateGrid(1);

% ctilde is the optimal choice for consumption if the borrowing
% constraint were relaxed only in the current period.
if log_c == 0
    temp = griddedInterpolant(xs,ctilde(xi),'linear','linear');
else
    temp = griddedInterpolant(xs,log(ctilde(xi)),'linear','linear');

end

mu0_fun = temp;
ctilde = temp(stateGrid);


% Step 3: compute stationary distribution of a




% Start by simulating T periods
param(2) = rt; 


[ai,~,~,api,~,~,~,~,~,~,~] = bc_endsignals_sim_fast_u(w,param,yi,eps_etai,reset_shocks, b,mu0_fun, ctilde, stateGrid,stateGrid_step,stateGrid_size, log_c, ex_signals, int_nodes, int_weights,normpdf_nodes);


conv_mat2 = mean(api(end-smooth_wind*2+1:end-smooth_wind,:),2);
conv_mat1 = mean(api(end-smooth_wind+1:end,:),2);

if  abs(mean(conv_mat1) - mean(conv_mat2)) > crit_dist
    disp(['r = ', sprintf('%1.5f' , r), '     !Distribution did not converge!']) 
else
    disp(['r = ', sprintf('%1.5f' , r)]) 
end

% Step 4: compute aggregate assets by integrating the distribution of a
A = mean([conv_mat1; conv_mat2]);



conv_crit = A - K;

end